package com.scu.bank.web;
import com.scu.bank.core.jo.Result;
import com.scu.bank.core.jo.ResultGenerator;
import com.scu.bank.model.pojo.AttachFile;
import com.scu.bank.service.AttachFileService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* Created by pmeng on 2021/01/03.
*/
@RestController
@RequestMapping("/attach/file")
public class AttachFileController {
    @Autowired
    private AttachFileService attachFileService;

    @PostMapping("/add")
    public Result add(@RequestBody AttachFile attachFile) {
        attachFileService.save(attachFile);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/delete")
    public Result delete(@RequestBody List<String> ids) {
        if (ids == null){
            return ResultGenerator.genFailResult("不能为空");
        }
        attachFileService.deleteByIds(ids);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody AttachFile attachFile) {
        attachFileService.update(attachFile);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/detail")
    public Result detail(@RequestParam String id) {
        AttachFile attachFile = attachFileService.getById(id);
        return ResultGenerator.genSuccessResult(attachFile);
    }

    @PostMapping("/list")
    public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageInfo<AttachFile> pageInfo = attachFileService.list(page, size);
        return ResultGenerator.genSuccessResult(pageInfo);
    }
}
